package cn.ywsj.ywsjmidtier.service.impl;

import cn.ywsj.ywsjmidtier.common.Connect;
import cn.ywsj.ywsjmidtier.entity.JUserMsg;
import cn.ywsj.ywsjmidtier.entity.XUserMsg;
import cn.ywsj.ywsjmidtier.service.LoginService;
import com.alibaba.fastjson.JSONObject;
import com.mzlion.easyokhttp.HttpClient;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
   @Override
   public String xsxLogin(XUserMsg xUserMsg) {
       //取code
       String url = "/captcha/getimageverifycode";
       //登录
       String url2 = "/wechat/loginenter";
       String xsx = HttpClient.post(Connect.XSX_URL+url).asString();
       JSONObject jsonObject = JSONObject.parseObject(xsx);
       String code = jsonObject.get("obj").toString();
       JSONObject jsonObject2 = JSONObject.parseObject(code);
       String code2 = jsonObject2.get("capText").toString();
       String xsxlogin = HttpClient.post(Connect.XSX_URL+url2)
               .param("userName", xUserMsg.getUserName())
               .param("passwd", xUserMsg.getPasswd())
               .param("sysCode",code2)
               .param("loginType", xUserMsg.getLoginType())
               .asString();
       return xsxlogin;
   }
    @Override
    public String javaShopLogin(JUserMsg jUserMsg) {
      String url = "/buyer/passport/login";
      String javalogin = HttpClient.post(Connect.SHOP_URL+url)
              .param("username",jUserMsg.getUsername())
              .param("password",jUserMsg.getPassword())
              .param("captcha",jUserMsg.getCaptcha())
              .param("uuid",jUserMsg.getUuid())
              .param("scene",jUserMsg.getScene())
              .asString();
       return javalogin;
    }
}
